-- round_self_recover2
-- created by panyl
-- 每回合回复

return {
    apply = function(prop, baseValue)
        return math.modf(prop[3] * baseVAlue / 1000);
    end,

    -- 每回合触发
    trigger = function(who, prop, arg)
        local attrib = tostring(prop[2]);

        -- 目前只有hp、mp
        assert(attrib == "hp" or attrib == "mp");

        local max = who:queryAttrib("max_hp");
        local curr = who:queryAttrib("hp");
        if attrib == "mp" then
            max = who:queryAttrib("max_mp");
            curr = who:queryAttrib("mp");
        end

        local value = tonumber(prop[3]);

        trace("round_self_recover2", "max = %d, curr = %d, value = %d", max, curr, value);

        -- 不能超过上限
        value = math.min(value, max - curr);

        if value <= 0 then
            return 0;
        end

        if who.type == OBJECT_TYPE_USER then
            BonusM.doBonus({ 2, attrib, value, }, "round_self_recover2");
            EventMgr.fire(event.NEED_REFRESH_ATTRIB, {attrib});
        else
            who:addAttrib(attrib, value);
        end

        return value;
    end,

    record = function(target, prop, path)
        return false;
    end
};
